<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <?php include 'inc/head.php'; ?>
  <style>
  html {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .table>:not(caption)>*>th {
    background-color: #EEE;
  }

  .table>:not(caption)>*>td {
    background-color: white;
  }

  label {
    padding: 5px 20px;
    cursor: pointer;
    margin-bottom: 0;
    font-weight: unset;
  }

  input[type=checkbox],
  input[type=radio] {
    margin: 4px 5px 0 0;
  }
  </style>
</head>

<body>
  <?php include 'inc/header.php'; ?>

  <div class="container">
    <form action="<?php echo M('admin', 'role', 'edit_action', $this->id); ?>" method="post">

      <table class="table table-sm table-bordered table-hover">
        <tbody>
          <tr>
            <th><label><input class="form-check-input" type="checkbox" id="chn">频道管理</label>
            </th>
            <td>
              <?php echo getChannelPriv(0, $this->id, $priv); ?>
            </td>
          </tr>

          <?php
          $priv_label = $GLOBALS['lang']['priv_label'];
          $priv_label_str = '#' . array_str(array_keys($priv_label), ',#');
          $priv_array = $GLOBALS['lang']['priv'];
          foreach ($priv_label as $key => $label) {
            echo '<tr><th><label><input class="form-check-input" type="checkbox" id="' . $key . '" status="0">' . $label . '</label></th><td>';
            foreach ($priv_array[$key] as $k => $v) {
              echo '<label for="' . $k . '"><input class="form-check-input" type="checkbox" name="' . $k . '" id="' . $k . '" value="' . $k . '" ' . (in_array($k, $priv) ? 'checked="checked"' : '') . '>' . $v . '</label>';
            }
            echo '</td></tr>';
          }
          ?>
        </tbody>
      </table>

      <div class="d-grid gap-2">
        <button type="submit" id="save" class="btn btn-primary">提交</button>
      </div>

    </form>
  </div>

  <?php include 'inc/footer.php'; ?>

  <!-- js -->
  <script>
  $(function() {
    $('#chn,<?php echo $priv_label_str; ?>').click(function() {
      var p = $(this).parent().parent().parent();
      var v = $(this).attr('status');
      if (v == 1) {
        p.find('input').prop('checked', false);
        $(this).attr('status', '0');
      } else {
        p.find('input').prop('checked', true);
        $(this).attr('status', '1');
      }
    });
    $('.common_table th>label>input').click(function() {
      var p = $(this).parent().parent().parent();
      var v = $(this).attr('status');
      if (v == 1) {
        p.find('input').prop('checked', false);
        $(this).attr('status', '0');
      } else {
        p.find('input').prop('checked', true);
        $(this).attr('status', '1');
      }
    });
  })
  </script>
</body>

</html>